package com.momo.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Topic 是通过routingKey来进行路由的
 */
@Configuration
public class TopicConfig {

    @Bean
    Queue queue1(){
        return new Queue("name");
    }

    @Bean
    Queue queue2(){
        return new Queue("age");
    }

    @Bean
    Queue queue3(){
        return new Queue("sex");
    }

    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange("momo_topic",true,false);
    }

    @Bean
    Binding nameBinding1(){
        return BindingBuilder.bind(queue1()).to(topicExchange()).with("name.#");
    }
    @Bean
    Binding nameBinding2(){
        return BindingBuilder.bind(queue2()).to(topicExchange()).with("age.#");
    }
    @Bean
    Binding nameBinding3(){
        return BindingBuilder.bind(queue3()).to(topicExchange()).with("sex.#");
    }
}
